<style type="text/css">
</style>

<div class="filter-content">
<div class="filter">
    <div class="f1">请选择时间：</div>
    <div class="f1 item" style="margin: 0px 20px 0px 0px;">
        <input type="text" class="am-form-field" placeholder="起始日期" id="start"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    <div class="f2 item">
        <input type="text" class="am-form-field" placeholder="结束日期" id="end"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    
    <div class="f5" style="margin-left: 30px;">
        <button class="am-btn btn">查看</button>
    </div>
    <div class="clear"></div>
</div>
</div>

<div style="margin:10px 10px 10px 0px;">
<table class="am-table am-table-bordered am-table-striped am-table-compact" id="result-table">
  <thead>
  <tr>
    <th>时间</th>
    <th>类型</th>
    <th>金额</th>
    <th>余额</th>
    <th>备注</th>
    <th>状态</th>
  </tr>
  </thead>
  <tbody>
  </tbody>
</table>
<div class="summary">
    共<span class="red total">0</span>条记录，当前页：<span class="page red">1/1</span>
</div>
<ul data-am-widget="pagination" class="am-pagination am-pagination-select">
    <li class="am-pagination-prev">
        <a href="#" class="">上一页</a>
    </li>

    <li class="am-pagination-next">
        <a href="#" class="">下一页</a>
    </li>
</ul>
</div>

<script>
    // 填充数据
    function fill_table(list) {
        var table = $("#result-table tbody");
        table.empty();
        var ids = [];
        for (var i in list) {
            var d = list[i];
            var tr = $("<tr></tr>");
            tr.append("<td>" + d.start);
            tr.append("<td>" + Util.convertLogType(d.type) + "</td>");
            tr.append("<td class='red'>" + (d.amount/100) + "</td>");
            tr.append("<td>" + (d.balance/100) + "</td>");
            tr.append("<td>" + (d.memo || '无') + "</td>");

            if (d.state == 1) tr.append("<td>等待中</td>");
            if (d.state == 1) tr.append("<td>已通过</td>");
            if (d.state == 2) tr.append("<td>已拒绝</td>");
            if (d.state == 3) tr.append("<td>已完成</td>");
            table.append(tr);
        }
    }

    var currPage = 1;
    var totalPage = -1;
    var f = function(page) {
        var s = $("#start").val(),
            e = $("#end").val();
        var data = {
            pageSize: 200,
            pageNum: page,
        };
        if (s) data.start = s;
        if (e) data.end = e;
        CMD.query_account_log2(data, function(data) {
            totalPage = data.page;
            fill_table(data.list);

            $(".summary .total").html(data.number);
            $(".summary .page").html(currPage + "/" + totalPage);
        });
    }
    $(".button .am-btn").click(function() {
        totalPage = -1;
        currPage = 1;
        f(currPage);
    });
    $(".am-pagination-prev a").click(function() {
        if (currPage <= 1) return;
        currPage--;
        f(currPage);
    });
    $(".am-pagination-next a").click(function() {
        if (currPage >= totalPage) return;
        currPage++;
        f(currPage);
    });

    ME.cb = function() {
        ME.cb = null;
        f(1);
    }
</script>
